package com.jfirer.validator.validation;

import javax.validation.ConstraintValidatorFactory;
import javax.validation.MessageInterpolator;
import javax.validation.ParameterNameProvider;
import javax.validation.TraversableResolver;
import javax.validation.Validator;
import javax.validation.ValidatorContext;
import com.jfirer.validator.PropertyValueDescriptorFactory;

public class ValidatorContextImpl implements ValidatorContext
{
    private MessageInterpolator            messageInterpolator;
    private ConstraintValidatorFactory     constraintValidatorFactory;
    private ParameterNameProvider          parameterNameProvider;
    private PropertyValueDescriptorFactory propertyValueDescriptorFactory;
    
    public ValidatorContextImpl(MessageInterpolator messageInterpolator, ConstraintValidatorFactory constraintValidatorFactory, ParameterNameProvider parameterNameProvider, PropertyValueDescriptorFactory propertyValueDescriptorFactory)
    {
        this.messageInterpolator = messageInterpolator;
        this.constraintValidatorFactory = constraintValidatorFactory;
        this.parameterNameProvider = parameterNameProvider;
        this.propertyValueDescriptorFactory = propertyValueDescriptorFactory;
    }
    
    @Override
    public ValidatorContext messageInterpolator(MessageInterpolator messageInterpolator)
    {
        this.messageInterpolator = messageInterpolator;
        return this;
    }
    
    @Override
    public ValidatorContext traversableResolver(TraversableResolver traversableResolver)
    {
        return this;
    }
    
    @Override
    public ValidatorContext constraintValidatorFactory(ConstraintValidatorFactory factory)
    {
        constraintValidatorFactory = factory;
        return this;
    }
    
    @Override
    public Validator getValidator()
    {
        return new ValidatorImpl(parameterNameProvider, messageInterpolator, constraintValidatorFactory, propertyValueDescriptorFactory);
    }
    
    @Override
    public ValidatorContext parameterNameProvider(ParameterNameProvider parameterNameProvider)
    {
        this.parameterNameProvider = parameterNameProvider;
        return this;
    }
    
}
